/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ma.projet.ejbs;


import java.util.Calendar;
import java.util.Date;
import java.util.List;
import ma.projet.abstracts.AbstractFacade;
import ma.projet.local.IncidentFacadeLocal;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TemporalType;
import ma.projet.entities.Incident;

/**
 *
 * @author Maison
 */
@Stateless
public class IncidentFacade extends AbstractFacade<Incident> implements IncidentFacadeLocal {
    @PersistenceContext(unitName = "ValorisationPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public IncidentFacade() {
        super(Incident.class);
    }
    @Override
    public int NbrIcidentWeek(Date deb,Date fin){
     
        List<Incident> liste=em.createNamedQuery("Incident.findByWeek").setParameter("debut", deb,TemporalType.TIMESTAMP).setParameter("fin", fin,TemporalType.TIMESTAMP).getResultList();
       
        return liste.size();
    }
    @Override
    public int NbrIcidentWeeksous(Date deb,Date fin,Long sous){
      
        List<Incident> liste=em.createNamedQuery("Incident.findByWeekSous").setParameter("debut", deb,TemporalType.TIMESTAMP).setParameter("fin", fin,TemporalType.TIMESTAMP).setParameter("sous", sous).getResultList();
 
        return liste.size();
    }
 @Override
    public int NbrIcidentDay(Date deb){
        Calendar c=Calendar.getInstance();
        c.setTime(deb);
        c.add(Calendar.HOUR, 23);
        c.add(Calendar.MINUTE, 59);
        c.add(Calendar.SECOND, 59);
        Date f=c.getTime();
        List<Incident> liste=em.createNamedQuery("Incident.findByDebutIncident").setParameter("debutIncident", deb,TemporalType.TIMESTAMP).setParameter("f",f).getResultList();
       
        return liste.size();
    }
}
